
DM "log; clear; ";

*****************************************************************************
* Program: MASTER					   						
* 																			
* Description: Master program for UDT analysis for PVSCC. Requires the 
* 			SAS programs listed below in the folder specified by directory.
*			Also requires the formats.sas7bcat format file and upload_data.cpt 
*			datafile (stored in folder specified by the lib path), the 
*			latter of which contains the datafile data_export.sas7bdat. 
*						
* Last modified: FEB 10, 2016											
* Created by: Martin Wegman													
*****************************************************************************;

* Path for directory of SAS programs;
%let directory = ;

* Path for output rtf and pdfs;
%let out_dir = ;

* Path for analysis data products and starting dataset;
%let lib = ;

* File name of starting analytic dataset;
filename importin "&lib\upload_data.cpt";

* Library for analysis data products;
libname loc "&lib";

* Set working directory;
x "cd &directory";

OPTIONS FMTSEARCH = ( loc );

*Include SAS analysis macros;
%include 'templates.sas';
%include 'score.sas';
%include 'missing_stage1.sas';
%include "compute_anyuse.sas";
%include 'patterns.sas';
%include 'compute_events.sas';
%include 'print_events.sas';
%include 'KMtemplate.sas';
%include 'missing_stage2.sas';
%include 'propensity.sas';
%include 'print_propensity.sas';
%include 'cox_analysis.sas';
%include 'table1.sas';
%include 'table_s2.sas';
%include 'table.sas';
%include 'plot_cll_diffs.sas';

* Import analytic dataset;
proc cimport infile=importin library=loc memtype=data; run;

proc contents data = loc.data_export; run;

* See figure1.R for Figure 1 plotting;

%let in = data_export;
%let out = missing_1st_stage;
%score(&in,&out);

%let in = missing_1st_stage;
%table1(&in);

%let in = missing_1st_stage;
%let out = compute_anyuse;
%missing_stage1(&in,&out);

%let in = missing_1st_stage;
%table_s2(&in);

%let in = compute_anyuse;
%let out = patterns;
%compute_anyuse(&in,&out);

%let in = patterns;
%let out = compute_events;
%patterns(&in,&out);

%let in = compute_events;
%let out = print_events;
%compute_events(&in,&out);

%let in = print_events;
%print_events(&in);

%let in = print_events;
%let out = propensity;
%missing_stage2(&in,&out);

%let in = propensity;
%let out = cox_analysis;
%propensity(&in,&out);

%let in = cox_analysis;
%print_propensity(&in);

%let in = cox_analysis;
%cox_analysis(&in); * Produces mydata.xpt files for R;

*Run R code file for calculating splines;
* CLL Diffs Compute.R

*Import data back from R;
proc import REPLACE
	datafile="&lib\diffs.dbf" 
	out=loc.diff 
	dbms=dbf;
run;

%let in = diff;
%plot_cll_diffs(&in);



